﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace peonwar
{
    public class Button : Sprite
    {
        // Utile pour numéroter les bouttons (de 1 a 9 pour les bouttons d'unité par exemple)
        public int UnitType;

        public Button(Vector2 position)
        {
            this.Position = position;
        }

        public Button(Vector2 position, Texture2D text)
        {
            this.Position = position;
            this.Texture = text;
        }

        public Button(Vector2 position, Texture2D text, int type)
        {
            this.Position = position;
            this.Texture = text;
            this.UnitType = type;
        }

        public virtual bool IsPressed(MouseState mouse)
        {
            bool result = mouse.LeftButton == ButtonState.Pressed
                && mouse.X > Position.X - Texture.Width / 2
                && mouse.X < Position.X + Texture.Width / 2
                && mouse.Y > Position.Y - Texture.Height / 2
                && mouse.Y < Position.Y + Texture.Height / 2
                && Game.CanClickLeft;
            if (result)
                Game.CanClickLeft = false;
            return result;
        }

        public virtual bool IsTouched(MouseState mouse) // Normalement c'est OnHover... IsTouched c'est juste chelou...
        {
            bool result = 
                   mouse.X > Position.X - Texture.Width / 2
                && mouse.X < Position.X + Texture.Width / 2
                && mouse.Y > Position.Y - Texture.Height / 2
                && mouse.Y < Position.Y + Texture.Height / 2;
            return result;
        }

        public virtual void Draw(SpriteBatch spriteBatch)
        {
            // La "Position" est au centre du sprite
            spriteBatch.Draw(Texture, new Vector2(Position.X - Texture.Width / 2 , Position.Y - Texture.Height / 2), Color.White);
        }
    }
}
